package com.coderman.basketball.statistics.service;

import com.coderman.basketball.statistics.context.DataBO;
import com.coderman.basketball.statistics.context.GameDataBO;
import com.coderman.basketball.statistics.context.GamePlayerDataBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Description:
 * date: 2021/5/27
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Service
public class DataServiceImpl implements DataService{

    @Autowired
    private CacheService cacheService;

    @Override
    public void updateScore(DataBO dataBO) {
        //1.更新缓存数据
        GameDataBO gameDataBO = cacheService.getGameData(dataBO.getGameId());

        //主队得分
        if(gameDataBO.getMainTeamName().equals(dataBO.getTeamName())){
            gameDataBO.incrClientTeamScore(dataBO.getCount());
        }else {
            gameDataBO.incrMainTeamScore(dataBO.getCount());
        }

        //增加球员分数
        GamePlayerDataBO gamePlayerDataBO = cacheService.getGamePlayerDataBO(dataBO.getPlayerId());
        gamePlayerDataBO.incrScore(dataBO.getCount());

        //todo 持久化-更新操作 GameDataBO  GamePlayerDataBO

    }

    @Override
    public void updateDataKey(DataBO dataBO) {
        GameDataBO gameDataBO = cacheService.getGameData(dataBO.getGameId());
        GamePlayerDataBO gamePlayerDataBO = cacheService.getGamePlayerDataBO(dataBO.getPlayerId());
        //主队球员发起事件，球队角度事件统计
        if(gameDataBO.getMainTeamName().equals(dataBO.getTeamName())){
            gameDataBO.incrMainTeamKeyValue(dataBO.getKey(),dataBO.getCount());
        }else {
            gameDataBO.incrClientTeamKeyValue(dataBO.getKey(),dataBO.getCount());
        }
        //更新球员统计数据，球员角度事件统计
        gamePlayerDataBO.incrKeyValue(dataBO.getKey(),dataBO.getCount());
        //todo 持久化-更新操作 GameDataBO  GamePlayerDataBO

    }
}
